<?php
include 'includes/application_top.inc';
include 'includes/paginate.php';
include 'auth.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Easy Living - Responsive Real Estate Template">
<meta name="keywords" content="Themes, real estate, responsive, themeforest, Templates">
<meta name="author" content="Rype Pixel [Chris Gipple]">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User information</title>
<!-- html5 support in IE8 and later -->
<script src="../../html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<!-- CSS file links -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/responsive.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<!-- Start Header -->
<?php include 'includes/header.php';?>
<!-- End Header -->
<!-- start subheader -->
<p>&nbsp;</p>
<!-- start recent properties -->
<script>
    function errorMess()
    {
        alert("You don’t have Permission");
    }
</script>

<section class="properties">
    <div class="container"><?php include 'includes/left.php';?>
        <div class="row">
            <div class="col-sm-6">
                <div class="propertyItem">
                	<!--  onsubmit="validate();"-->
                	<!--<h1>Report</h1>-->
                    <table border="1" class="propertyDetails">
                       <tr class="tabHead">
                            <td>First Name</td>
                            <td>Last Name</td>
                            <td>Email</td>
                            <td>Date/Time</td>
                            <td>User Rights</td>
                        </tr>
                    	<?php      

                     	$user_id = $_SESSION['u_id'];
						$RefAuthid = 6;
						 $authCheck  = authentication($RefAuthid,$user_id); 
                    	$per_page = 5;  
                    	  $select = "Select * From url_users ORDER BY u_id DESC";
						$result = mysql_query($select);
						$total_results = mysql_num_rows($result);
						
						
						$pagesUrl = "tpages=".@$_REQUEST['tpages']."&page=".@$_REQUEST['page'];
						$total_pages = ceil($total_results / $per_page);//total pages we going to have
						
						//-------------if page is setcheck------------------//
						if (isset($_GET['page'])) {
						    $show_page = $_GET['page'];             //it will telles the current page
						    if ($show_page > 0 && $show_page <= $total_pages) {
						        $start = ($show_page - 1) * $per_page;
						        $end = $start + $per_page;
						    } else {
						        // error - show first set of results
						        $start = 0;              
						        $end = $per_page;
						    }
						} else {
						    // if page isn't set, show first set of results
						    $start = 0;
						    $end = $per_page;
						}
						// display pagination
						$page = intval(@$_GET['page']);
						
						$tpages=$total_pages;
						if ($page <= 0)
						    $page = 1;
                    	
						 $reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;
						 
                    echo '<div class="pagination"><ul>';
                    if ($total_pages > 1) {
                        echo paginate($reload, @$show_page, $total_pages);
                    }
                    echo "</ul></div>";
					
					for ($i = $start; $i < $end; $i++) {
                        // make sure that PHP doesn't try to show results that don't exist
                        if ($i == $total_results) {
                            break;
                        }
			
                        $rowColor = '';
			
							  
                       $id= mysql_result($result, $i, 'u_id');
					   $first_name  =mysql_result($result, $i, 'first_name');
					   $last_name= mysql_result($result, $i, 'last_name');
					   $email= mysql_result($result, $i, 'email');
                        // echo out the contents of each row into a table
                        if(isset($_REQUEST['id']))
                        {
                            $rowId = $_REQUEST['id'];
                            if($rowId == $id)
                            {
                                $rowColor = 'background-color: #E7E7E7;';
                            }
                        }
                        
                        echo '<tr class="propertyDetails1" style="'.$rowColor.'">';
                        echo '<td>' .$first_name . '</td>';
                        echo '<td>' . $last_name. '</td>';
						echo '<td>' . $email. '</td>';
                        echo '<td>' . mysql_result($result, $i, 'create_datetime') . '</td>';
                       if($authCheck==1)
					   {
					   	echo '<td><a href="user.php?ac=PER&'.$pagesUrl.'&id='.$id.'" >Change User Rights</a></td>';
					   }else
					   	{
					   	echo '<td onclick="errorMess()">Change User Rights</td>';
					   	}
                        
                        echo "</tr>";
                    }  
					?>                       
                    </table>
                    
                    
				<hr />
				
				 <?php 
                
					  	$arr ="";
					  	if(isset($_REQUEST['id'])&& $authCheck ==1)
						{
							
							 
					   	 $sqlRef = "Select * FROM user_rights_ref WHERE user_id=".$_REQUEST['id'];
					  	 $query = mysql_query($sqlRef);
					  	 
					  	$arr = array();
						 while($row = mysql_fetch_array($query))
						 {
						 	 $arr[] = $row['rights_id'];
						 }
						 
					//  print_r($arr);
					  	 
						if(@$_REQUEST['ac']=="pmsg"){ echo '<p style="color: green">User Rights successfully set</p>';}						
						if(@$_REQUEST['ac']=="PER")	{//ac=PER
						?>						
					<form name="form" method="post" id="form" action="action_user.php">
						<input type="hidden" id="id" name="id" value="<?php echo $_REQUEST['id'];?>" />
					    <table border="0" class="propertyDetails">
					  	<tr><td colspan="2"><h1>User Rights</h1></td></tr>					  	
					  	<tr><td><?php 
					  	
						 $select = "Select * from rights";
						 $query = mysql_query($select);
					 
                        $i=0;
						$y=0;
              			 while ($rowp = mysql_fetch_array($query))
						 {
						  ?>
							<input type="checkbox" name="rightsid_<?php echo $i;?>" value="<?php echo $rowp['rights_id'];?>" <?php if (in_array($rowp['rights_id'],$arr)) { ?> checked="checked" <?php  } ?> /> &nbsp;<?php echo $rowp['rights_name'];?>
							<?php
						 	//echo '<input type="checkbox" name="rightsid_'.$i.'" id="rightsid" value="'.$rowp['rights_id'].'" />&nbsp;'.$rowp['rights_name'];
							//echo "&nbsp;&nbsp;&nbsp;&nbsp;";
							
						 $i++;$y++;}
					  	?>
					  	 
					  	</td></tr> 
					     <tr><td>
						<input id="submit" type="submit" value="Submit" name="submit" accesskey="l" /></td></tr>       
					</table></form>	
					<?php }  }?>
                </div>
            </div>
        </div><!-- end row -->
    </div><!-- end container -->
</section>
<!-- end recent properties -->
<div class="bottomBar">
    <div class="container">
    <!--    <p>CopyRight @ News Nation</p>-->
    </div>
</div>

<!-- JavaScript file links -->
<script src="js/jquery.js"></script>			<!-- Jquery -->
<script src="js/bootstrap.min.js"></script>  <!-- bootstrap 3.0 -->
<script src="js/respond.js"></script>


	<script type="text/javascript">
	function redirecttest (argument) {
	  <!--
   var retVal = confirm("Do you want to delete ?");
   if( retVal == true ){
//      alert("User wants to continue!");
      window.location="action.php?URE=DELETE&<?php echo $pagesUrl;?>&id="+argument;
	  return true;
   }else{
    //  alert("User does not want to continue!");
	  return false;
   }
//-->
	}

</script>

<script type="text/javascript">
    function validate() {
        var url = document.getElementById("url").value;
        var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
        if (pattern.test(url)) {
            alert("Url is valid");
            return true;
        }else
        {
        	alert("Url is not valid!");
            return false;

        } 
            
    }
</script>
</body>
</html>